﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using POSSystem.BLL;

namespace WebUI.Controls
{
    public partial class RequestContent : BaseEditControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            base.Page_Load(sender, e);

        }

        public string Name
        {
            get { return lblName.Text; }
            set { lblName.Text = value; }
        }

        public string Sent
        {
            get { return lblSent.Text; }
            set { lblSent.Text = value; }
        }

        public string Title
        {
            get { return lblTitle.Text; }
            set { lblTitle.Text = value; }
        }

        public string Content
        {
            get { return litContent.Text; }
            set { litContent.Text = value; }
        }

        public string Email
        {
            get { return lblEmail.Text; }
            set { lblEmail.Text = value; }
        }

        public string Address
        {
            get { return lblAddress.Text; }
            set { lblAddress.Text = value; }
        }

        public void LoadByID(int id)
        {
            CustomerRequests r = new CustomerRequests();
            string temp = "; &nbsp;";
            r.LoadByPrimaryKey(id);
            if (r.RowCount > 0)
            {
                string webPath = Utilities.GetConfigAppSetting("RequestFile");
                AttachedFiles files = AttachedFiles.GetFiles(r.ID, AttachedFiles.FileCategory.CustomerRequest);
                string html = "";
                for (int i = 0; i < files.RowCount; i++)
                {
                    string path = webPath + files.s_Path.Replace("~", "");
                    html += string.Format("<a href='{0}'>{1}</a>", path, files.s_FileName) + temp;
                    files.MoveNext();
                }
                if (html != "")
                    html = html.Substring(0, html.Length - temp.Length);
                else
                    html = "n/a";
                litAttachment.Text = html;
                this.Name = r.s_Requestor;
                this.Title = r.s_Title;
                this.Content = r.s_Content;
                this.Sent = r.s_CreatedDate;
                this.Email = r.s_Email != "" ? "<a href='mailto:" + r.s_Email + "'>" + r.s_Email + "</a>" : "";
                this.Address = r.s_Address;
            }
        }
    }
}